View Javadoc

1   /*
2    * Copyright 2007 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   *
16   *  @author Dasarath Weeratunge, Hannes Erven, Georg Hicker
17   */
18  package org.apache.kandula;
19  
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.util.Properties;
23  
24  /***
25   * @author Dasarath Weeratunge, Hannes Erven, Georg Hicker
26   *  
27   */
28  public class KandulaConfig {
29  
30  	private static final String PROPERTY_FILE = "kandula.properties";
31  
32  	private static final String LOCAL_SERVICE__PROPERTY = "kandula.localService";
33  
34  	private static final String PREFERRED_SERVICE__PROPERTY = "kandula.preferredCoordinationService";
35  
36  	private static KandulaConfig instance = new KandulaConfig();
37  
38  	private Properties properties = null;
39  
40  	private KandulaConfig() {
41  		this.properties = new Properties();
42  		loadProperties();
43  	}
44  
45  	public static KandulaConfig getInstance() {
46  		return instance;
47  	}
48  
49  	private void loadProperties() {
50  		InputStream in = getClass().getClassLoader().getResourceAsStream(PROPERTY_FILE);
51  
52  		try {
53  			this.properties.load(in);
54  			in.close();
55  		} catch (IOException e) {
56  			e.printStackTrace();
57  			throw new RuntimeException(e);
58  		}
59  	}
60  
61  	public String getContext() {
62  		return this.properties.getProperty(LOCAL_SERVICE__PROPERTY);
63  	}
64  
65  	/***
66  	 * Return the configured local kandula services endpoint base URL, eg.
67  	 * http://test1.kandula.apache.org:8280/axis/services/
68  	 * @return String-URL
69  	 */
70  	public String getLocalServicesURL() {
71  		return this.properties.getProperty(LOCAL_SERVICE__PROPERTY);
72  	}
73  
74  	/***
75  	 * Return the configured preferred kandula coordination services endpoint base URL, eg.
76  	 * http://my-favorite-coordinator.bar.foo.org:8180/axis/services/
77  	 * @return String-URL
78  	 */
79  	public String getKandulaServicesURL(){
80  		final String externalURL = this.properties.getProperty(PREFERRED_SERVICE__PROPERTY);
81  
82  		if (externalURL != null && externalURL.length()>0)
83  			return externalURL;
84  		
85  		return getContext();
86  	}
87  }